package com.example.teesystem.entityDto;

import com.example.teesystem.common.utils.FileUtil;
import com.example.teesystem.common.utils.TimeUtil;
import com.example.teesystem.entity.User;
import lombok.Data;
import org.springframework.beans.BeanUtils;

/**
 * @author pxr
 * @data 2022/4/18 20:33
 */
@Data
public class StudentDto {
    private Integer id;

    private String username;

    /**
     * 性别
     */
    private String gender;

    /**
     * 生日
     */
    private String birthday;

    /**
     * 姓名
     */
    private String myName;
    /**
     * 学院
     */
    private String academy;

    /**
     * 年级
     */
    private Integer grade;

    /**
     * 班级
     */
    private Integer classes;

    /**
     * 邮箱
     */
    private String mail;

    /**
     * 用户类型(0：超级管理员，1教师，2：学生)
     */
    private String type;

    private Integer accountType;

    private String account_type;

    private String avatarUrl;

    public StudentDto(User user){
        BeanUtils.copyProperties(user,this);
        if(user.getAvatarUrl()!=null && !user.getAvatarUrl().equals("")){
            this.avatarUrl = FileUtil.FILE_PREFIX + user.getAvatarUrl();
        }
        try{
            this.birthday = TimeUtil.dateToString(user.getBirthday());
        }catch (Exception e){
            this.birthday = "";
        }
        try{
            if(user.getType() == 0){
                this.type = "超级管理员";
            }else if(user.getType() == 1){
                this.type = "教员";
            }else {
                this.type = "学员";
            }
        }catch (Exception e){
            this.type = "未知";
        }

        try{
            if(user.getType() == 1){
                this.account_type = "已禁用";
            }else {
                this.account_type = "正常使用";
            }
        }catch (Exception e){
            this.account_type = "未知";
        }

    }

}
